layui.config({
    base: '/static/js/lib/',
    version: new Date().getTime()
}).use(['layer', "table", "laytpl", "laydate"], function () {

    $ = layui.jquery;
    var layer = layui.layer;
    var laydate = layui.laydate;
    laydate.render({
        elem: '#beginTime' //指定元素
        , type: 'datetime'
    });

    $('.select').click(function () {
        $(this).addClass("active").siblings().removeClass("active");
        $.post("/phases/list", {parentId: $(this).attr("value")}, function (res) {
            if (res.code == "00000") {
                var phases = res.data;
                var html = "";
                for (var i = 0; i < phases.length; i++) {
                    html += '<a class="layui-btn phasesSelect" value="' + phases[i].id + '">' + phases[i].name + '</a>';
                }
                $('.phasesUl').html(html);
                // 下拉框选择
                $('.phasesSelect').click(function () {
                    $(this).addClass("active").siblings().removeClass("active");
                });
            } else {
                console.log(res);
            }
        });
    });


    $('.save').click(function () {
        var html = "<tr class='tr'>";
        $($('.scope th')).each(function () {
            var id = $(this).attr("id");
            if (id != 0) {
                html += '<td id="' + id + '"><input type="text" placeholder="1-15" class="layui-input">'
            } else {
                html += '<td id="0"><a class="layui-btn layui-btn-sm layui-btn-radius layui-btn-danger remove" >删除</a>'
            }
        });
        html += '</tr>';
        $('.scheme').append(html);

        $('.remove').click(function () {
            var tr = $(this).parents('tr');
            layer.confirm("是否删除", {icon: 0, title: '提示'}, function () {
                layer.msg("删除成功");
                tr.remove();
            });

        });

    });

    $('.random').click(function () {
        console.log($('#assessmentId').val());
        $.post("/random/save", {
            assessmentId: $('#assessmentId').val()
        }, function (res) {
            console.log(res);
            layer.msg(res.data);
            if (res.code == "00000") {
                var html = '<tr><td>' + res.data + '</td></tr>';
                $('.randomResult').append(html);
            } else {
                console.log(res);
            }
        });
    })

});